package von.seiji.cn.test;

/**
 * @Author: Amasawa Seiji
 * @Since: 2021/1/19 9:28
 * @Description: 暂无描述
 */

public class T11 {

        private static final int THREADS_CONUT = 20;
      //  public static AtomicInteger count = new AtomicInteger(0);

        private int count = 0 ;

        public void increase() {

            //count.incrementAndGet();
        }

        public static void main(String[] args) {
            Thread[] threads = new Thread[THREADS_CONUT];
            T11 test9 = new T11();

            for (int i = 0; i < THREADS_CONUT; i++) {
                threads[i] = new Thread(new Runnable() {
                    @Override
                    public synchronized void run() {

                            while (true){
                                synchronized (this){
                                if( test9.count > 50) break;
                                System.out.println("count = " +  test9.count ++);
                                try {
                                    Thread.sleep(500);
                                } catch (InterruptedException e) {}
                                    System.out.println(Thread.currentThread().getName()+":"+ test9.count);
                            }
                        }
                    }
                });
                threads[i].start();
            }
        }


}
